﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace cmdb.keede.entity.Migrations
{
    public partial class update_grouphost0213 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_GROUP_HO_REFERENCE_GROUP",
                table: "GroupHost");

            migrationBuilder.DropForeignKey(
                name: "FK_GROUP_HO_REFERENCE_VIRTUALH",
                table: "GroupHost");

            migrationBuilder.DropIndex(
                name: "IX_GroupHost_HostId",
                table: "GroupHost");

            migrationBuilder.DropColumn(
                name: "HostId",
                table: "GroupHost");

            migrationBuilder.AlterColumn<int>(
                name: "Status",
                table: "VirtualHostInfo",
                nullable: false,
                defaultValueSql: "((0))",
                oldClrType: typeof(int),
                oldUnicode: false,
                oldMaxLength: 10);

            migrationBuilder.AlterColumn<string>(
                name: "OSVersion",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 20,
                nullable: true,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "OS",
                table: "VirtualHostInfo",
                nullable: false,
                defaultValueSql: "((0))",
                oldClrType: typeof(int),
                oldUnicode: false,
                oldMaxLength: 32);

            migrationBuilder.AlterColumn<int>(
                name: "DeviceType",
                table: "VirtualHostInfo",
                nullable: false,
                defaultValueSql: "((0))",
                oldClrType: typeof(int),
                oldUnicode: false,
                oldMaxLength: 10);

            migrationBuilder.AddColumn<string>(
                name: "RelationKey",
                table: "GroupHost",
                unicode: false,
                maxLength: 20,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "RelationType",
                table: "GroupHost",
                nullable: false,
                defaultValueSql: "((0))");

            migrationBuilder.AddColumn<string>(
                name: "RelationValue",
                table: "GroupHost",
                unicode: false,
                maxLength: 50,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AddColumn<int>(
                name: "VirtualHostInfoId",
                table: "GroupHost",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_GroupHost_VirtualHostInfoId",
                table: "GroupHost",
                column: "VirtualHostInfoId");

            migrationBuilder.AddForeignKey(
                name: "FK_Group_REFERENCE_GroutHost",
                table: "GroupHost",
                column: "GroupId",
                principalTable: "Group",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_GroupHost_VirtualHostInfo_VirtualHostInfoId",
                table: "GroupHost",
                column: "VirtualHostInfoId",
                principalTable: "VirtualHostInfo",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Group_REFERENCE_GroutHost",
                table: "GroupHost");

            migrationBuilder.DropForeignKey(
                name: "FK_GroupHost_VirtualHostInfo_VirtualHostInfoId",
                table: "GroupHost");

            migrationBuilder.DropIndex(
                name: "IX_GroupHost_VirtualHostInfoId",
                table: "GroupHost");

            migrationBuilder.DropColumn(
                name: "RelationKey",
                table: "GroupHost");

            migrationBuilder.DropColumn(
                name: "RelationType",
                table: "GroupHost");

            migrationBuilder.DropColumn(
                name: "RelationValue",
                table: "GroupHost");

            migrationBuilder.DropColumn(
                name: "VirtualHostInfoId",
                table: "GroupHost");

            migrationBuilder.AlterColumn<int>(
                name: "Status",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(int),
                oldDefaultValueSql: "((0))");

            migrationBuilder.AlterColumn<string>(
                name: "OSVersion",
                table: "VirtualHostInfo",
                nullable: true,
                oldClrType: typeof(string),
                oldUnicode: false,
                oldMaxLength: 20,
                oldNullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "OS",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 32,
                nullable: false,
                oldClrType: typeof(int),
                oldDefaultValueSql: "((0))");

            migrationBuilder.AlterColumn<int>(
                name: "DeviceType",
                table: "VirtualHostInfo",
                unicode: false,
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(int),
                oldDefaultValueSql: "((0))");

            migrationBuilder.AddColumn<int>(
                name: "HostId",
                table: "GroupHost",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateIndex(
                name: "IX_GroupHost_HostId",
                table: "GroupHost",
                column: "HostId");

            migrationBuilder.AddForeignKey(
                name: "FK_GROUP_HO_REFERENCE_GROUP",
                table: "GroupHost",
                column: "GroupId",
                principalTable: "Group",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_GROUP_HO_REFERENCE_VIRTUALH",
                table: "GroupHost",
                column: "HostId",
                principalTable: "VirtualHostInfo",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
